package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 22:06 2020/3/30
 * @Description 汉明距离
输入: x = 1, y = 4
输出: 2
解释:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑
 */

import java.util.concurrent.locks.LockSupport;

public class LeetCode_461 {


    public int hammingDistance(int x, int y) {
        // 先进行异或操作，然后在按位与
        int z = x ^ y;

        int count = 0;
        // 按位与
        while (z != 0) {
            if ((z&1) == 1) count++;
            z >>= 1;
        }
        return count;
    }



}



